<?php
// +----------------------------------------------------------------------
// | ThinkCMF [ WE CAN DO IT MORE SIMPLE ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2019 http://www.thinkcmf.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: 小夏 < 449134904@qq.com>
// +----------------------------------------------------------------------
namespace app\admin\controller;

use app\admin\model\CommonModel;
use cmf\controller\AdminBaseController;
use app\admin\model\InfoSetModel;
use think\Db;

//信息设置
class InfoSetController extends AdminBaseController
{
    //编辑页面
    public function edit(){
        $post = Db::name('info_set')
            ->where('id',1)
            ->find();
        $commonModel = new CommonModel();
        $post['sign_rule'] = $commonModel->getPostContentAttr($post['sign_rule']);
        $post['grade_rule'] = $commonModel->getPostContentAttr($post['grade_rule']);
        $post['guess_rule'] = $commonModel->getPostContentAttr($post['guess_rule']);
        $post['invite_rule'] = $commonModel->getPostContentAttr($post['invite_rule']);
        $post['about_us'] = $commonModel->getPostContentAttr($post['about_us']);
        $this->assign('post',$post);
        return $this->fetch();
    }

    //编辑保存页面
    public function editPost(){
        $data = $this->request->param();

        $commonModel = new CommonModel();
        $data['sign_rule'] = $commonModel->setPostContentAttr($data['sign_rule']);
        $data['grade_rule'] = $commonModel->setPostContentAttr($data['grade_rule']);
        $data['guess_rule'] = $commonModel->setPostContentAttr($data['guess_rule']);
        $data['invite_rule'] = $commonModel->setPostContentAttr($data['invite_rule']);
        $data['about_us'] = $commonModel->setPostContentAttr($data['about_us']);
        //过滤data数组中的非数据表字段数据
        $infoSetModel = new InfoSetModel();
        $res = $infoSetModel->allowField(true)->save($data,['id'=>$data['id']]);
        if($res){
            $this->success('保存成功!', url('InfoSet/edit'));
        }else{
            $this->error('保存失败');
        }
    }
}